package usaco.c2009.march.gold;

import java.util.Scanner;

/*
 * p3210
 * USACO March 2009 - Gold
 * Hint: subtle technique required! two iterators (start from 1) to keep track of the two numbers that are considered lastly
 * once the candidate corresponding to function f_i is selected, the corresponding iterator increases.
 * the idea is that f_1 and f_2 are all increasing function.
 */

public class p3210 {

	static long c, a1, a2, b1, b2, d1, d2, n1, n2;
	static long[] S;
	static int N, size, x1, x2;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		c = scanner.nextLong();
		N = scanner.nextInt();
		a1 = scanner.nextLong();
		b1 = scanner.nextLong();
		d1 = scanner.nextLong();
		a2 = scanner.nextLong();
		b2 = scanner.nextLong();
		d2 = scanner.nextLong();
		
		x1 = x2 = 1;
		S = new long[N+1];
		
		S[1] = c;
		n1 = f1(c);
		n2 = f2(c);
		size = 1;
		
		while (size < N) {
			if (n1 < n2) {
				if (S[size] != n1) {
					++size;
					S[size] = n1;
				}
				x1++;
				n1 = f1(S[x1]);
//				System.out.println(n1);
			}
			else {
				if (S[size] != n2) {
					++size;
					S[size] = n2;
				}
				x2++;
				n2 = f2(S[x2]);
//				System.out.println(n2);
			}
		}
		
		System.out.println(S[size]);

	}
	
	public static long f1(long c) {
		return a1 * c / d1 + b1;
	}
	
	public static long f2(long c) {
		return a2 * c / d2 + b2;
	}

}
